package my.study.java.lang.reflect.Proxy.examples;


/**
 * 利用组合实现的
 * @author fanhongjie
 *
 */
public class SimpleAnimalProxy implements Animal {
	private Animal proxied;

	public static Animal createProxy(Class<? extends Animal> cls) {
		Animal animal = null;
		try {
			animal = new SimpleAnimalProxy(cls.newInstance());
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return animal;
		
	}
	public SimpleAnimalProxy(Animal proxied) {
		this.proxied = proxied;
	}

	public void eat() {
		pl("SimpleAnimalProxy.eat()");
		proxied.eat();
	}

	public void shout(String arg) {
		pl("SimpleAnimalProxy.shout(" + arg + ")");
		proxied.shout(arg);
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
}